# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/5 下午4:48
 @Author  : tgy
 
"""
import threading

flag = 0

cd1 = threading.Condition()
cd2 = threading.Condition()
cd3 = threading.Condition()

lock = threading.RLock()


def run01():
    ...
    global flag
    while True:
        if cd1.acquire():
            while flag != 0:
                cd1.wait()
            print('A')
            flag = 1
            cd1.release()
            cd2.notify()


def run02():
    ...
    global flag
    while True:
        if cd2.acquire():
            print('111')
            while flag != 1:
                cd2.wait()
            print('1111111')
            print('B')
            flag = 2
            cd2.release()
            cd3.notify()


def run03():
    ...
    global flag
    while True:
        if cd3.acquire():
            print('222')
            while flag != 2:
                cd3.wait()
            print('2' * 10)
            print('C')
            flag = 0
            cd3.release()
            cd1.notify()


def test01():
    ...

    t1 = threading.Thread(target=run01)
    t2 = threading.Thread(target=run02)
    t3 = threading.Thread(target=run03)
    t1.start()
    t2.start()
    t3.start()


if __name__ == '__main__':
    ...
    test01()
